package com.cs.pk.form.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import com.cs.pk.Activator;
import com.cs.pk.utils.FontUtil;

public class TitleControl {
	
	private String titleStr = null;
	private Font labelFont = null;
	private Image titleImage = new Image(null,"D:/workspace/codestriker/icons/ndstitle.gif");
	//private Image titleImage = Activator.getImageDescriptor("icons/ndstitle.gif").createImage();//new Image(null,"D:/workspace/codestriker/icons/ndstitle.gif");
	public TitleControl(String titleStr) {
		this.titleStr = titleStr;
	}
	
	public void createControl(Composite parent) {
		Composite titleHead = new Composite(parent ,SWT.NONE);
		titleHead.addDisposeListener(new DisposeListener(){

			public void widgetDisposed(DisposeEvent e) {
				System.out.println("disposed..");
                  dispose();				
			}
			
		});
		titleHead.setBackgroundImage(titleImage);
		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.grabExcessHorizontalSpace = true;
        gridData.heightHint = gridData.minimumHeight = titleImage.getBounds().height;
        
        gridData.verticalIndent = 0;
		gridData.horizontalIndent = 0;
		titleHead.setLayoutData(gridData);
		titleHead.setLayout(new GridLayout());
		
		Label label = new Label(titleHead, SWT.WRAP);
		label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true));
		label.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
		labelFont = FontUtil.adjustFont(label, 11, SWT.BOLD);
		label.setText(titleStr);
		titleHead.setBackgroundMode(SWT.INHERIT_DEFAULT);
		
	}
	
	public void dispose(){
		if(labelFont!=null){
		 labelFont.dispose();
		}
		if(titleImage!=null){
		 titleImage.dispose();
		}
	}

}
